#include <iostream>
#include <unistd.h>
#include <sys/types.h>
using namespace std;


int main()
{
    cout << "这是一个进程， pid: " << getpid() << " , ppid: " << getppid() << endl;

    pid_t id = fork();

    if(id == 0)
    {
        while(1)
        {
            cout << "我是子进程: pid: " << getpid() << " , ppid: " << getppid() << endl;
            sleep(1);
        }
    }
    else if(id > 0)
    {
        while(1)
        {
            cout << "我是父进程: pid: " << getpid() << " , ppid: " << getppid() << endl;
            sleep(1);
        }
    }
    else
    {

    }



//    while(1)
//    {
//        cout << "I am a process, my id is: " << getpid() << ",parent: " << getppid() << endl;
//        sleep(1);
//    }
//
    return 0;
}


